Reading Assignment 3
OpenMP Advanced
Write your answers in a PDF and upload the document on Gradescope for submission. The due date is given on Gradescope. Each question is worth 10 points.
Please watch the videos 13 through 18 and the slides before answering these questions.
Starter code for all the questions.
- Why is
#pragma omp task
typically preceded by
#pragma omp single
?
- In OpenMP,
firstprivate
variables must be initialized inside the task. True/False? Explain. - In
tree_postorder.cpp
, explain why we use theshared
clause on line 65 and 69.
For the next questions, please open slide 29 in Lecture_05.pdf
. Then answer these questions:
- Task T2 comes after T1. Always/Never/Sometimes. Explain.
- Task T2 comes after T4. Always/Never/Sometimes. Explain.
- Task T5 comes after T1. Always/Never/Sometimes. Explain.
- Tasks T4 and T5 may run concurrently. Yes/No/It depends. Explain.
- Task T5 comes after T1 and T3. Always/Never/Sometimes. Explain.
- This program prints out “d=6”. Yes/No/It depends. Explain.
- When both are correct, atomic is preferred over reduction in a for loop. True/False? Explain.
- Complete the todo in
entropy.cpp
. See lines 22, 31, 39, and 50. Turn in your code.
Slide Deck. Make sure you watch the corresponding video.
- Parallelize
bitonic_sort_lab.cpp
using OpenMP. Follow the instructions in the slides. You should make at least the following changes: parallelize thej
loop on line 86. Split thei
loop on line 84. Modify the functionBitonicSortPar
to parallelize thei
loop on line 169. Modify line 184 by adding anif
statement. Add and parallelize thej
loop as explained on slide 44. At the end, you should have three new#pragma omp
directives. Turn in your code. Turn in the output of your code without the-DNDEBUG
compile option.
If you compile your code without -DNDEBUG
, this will keep the assert
at the end. If you implement your code correctly, you should pass the assert
test at the end.
With the -DNDEBUG
option, the code will sort a longer array. You should see a speed up when using multiple threads. Run your code using
export OMP_NUM_THREADS=4; ./bitonic_sort